<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title></title>
		<link rel="stylesheet" type="text/css" href="js/elementUI/index.css"/>
		<link rel="stylesheet" href="css/main.css">
		
	</head>
	<body>
		<div class="main" id="app">
			<div class="contbox">
				<div class="title">{{name}}</div>
				<div class="inputbox">
					<div class="filebox">
						<span class="ts">请选择文件</span>
					　　<input type="file" id="file"> 
					</div>
					<button class="localbtn">上传许可文件</button>
				</div>
				<el-button class="localbtn btna" :disabled="isgoto" @click="goto">下一步<i class="el-icon-right" style="margin-left: 20px;"></i></el-button>
			</div>
			
		</div>
		<script src="js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/elementUI/index.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/axios.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			let vm = new Vue({
				el: '#app',
				data() {
					return{
						ip:"",
						isgoto:true,
						name:"",
					}
				},
				computed: {},
				created() {
					this.ip=window.location.origin;
				},
				mounted(){
					let _this=this;
					$('document').ready(function () {
						axios.get(_this.ip+"/license/getInfo").then(res=>{
							_this.name=res.data.title;
						});
						$(".filebox").on("change","input[type='file']",function(){
							var filePath=$(this).val();
							$(".ts").text("");
							$(".ts").text(filePath);
							
							var fileObj = document.getElementById("file").files[0];
							console.log(fileObj.name);
							if(fileObj.name=="license.lic"){
								//上传文件
								var form = new FormData(); // FormData 对象
								form.append("file", fileObj); // 文件对象
								var configs = {
									headers:{'Content-Type':'multipart/form-data'}
								};
								
								axios.post(_this.ip+"/license/upload",form ,configs).then(res=>{
									if(res.data.code==1){
										_this.$message.success('上传成功');
										//可以点击下一步
										_this.isgoto=false;
									}else{
										_this.$message.error(res.data.msg);
										_this.isgoto=true;
									}
								})
							}else{
								_this.$message.error('上传许可文件不正确！');
							}
							

						})
					});	
				}, 
				methods: {	
				  goto(){
					  window.location.href="license-install.html";
				  }
				}
			})
		</script>
	</body>
</html>
